package com.tianyi.lib.util;

import java.util.function.Consumer;

/**
 * 减少代码的if else使用率
 *
 * @author cuixuhui
 * @date 2018/10/01
 */
public final class Conditional {

    private Boolean conditional = false;

    public Conditional ifTrue(Consumer<Boolean> consumer){
        if (conditional) {
            consumer.accept(conditional);
        }
        return this;
    }

    public Conditional ifFalse(Consumer<Boolean> consumer){
        if (!conditional) {
            consumer.accept(conditional);
        }
        return this;
    }

    public static Conditional of(boolean conditional){
        Conditional condition = new Conditional();
        condition.conditional = conditional;
        return condition;
    }

}
